import {ElMessage, ElMessageBox, ElNotification} from 'element-plus'
import "element-plus/es/components/notification/style/css";

//封装全局toast
export const toast = (msg: string, type: string = "default") => {
    switch (type) {
        case "default":
            ElNotification({
                title: "提示",
                message: msg,
                type: "info",
            });
            break;
        case "success":
            ElNotification({
                title: "成功",
                message: msg,
                type: "success",
            });
            break;
        case "fail":
            ElNotification({
                title: "错误",
                message: msg,
                type: "error",
            });
            break;
        case "warning":
            ElNotification({
                title: "警告",
                message: msg,
                type: "warning",
            });
            return toast;
    }
};

// 普通信息提示
export function infoMsg(msgInfo) {
    ElMessage({
        type: 'info',
        showClose: true,
        dangerouslyUseHTMLString: true,
        message: msgInfo,
    })
}

// 成功提示
export function successMsg(msgInfo: string): void {
    ElMessage({
        type: 'success',
        showClose: true,
        dangerouslyUseHTMLString: true,
        message: msgInfo,
    })
}

// 错误提示
export function errorMsg(msgInfo: string): void {
    ElMessage({
        type: 'error',
        showClose: true,
        dangerouslyUseHTMLString: true,
        message: msgInfo,
    })
}

// 警告提示
export function warnMsg(msgInfo: string): void {
    ElMessage({
        type: 'warning',
        showClose: true,
        dangerouslyUseHTMLString: true,
        message: msgInfo,
    })
}

// 带一个确定按钮或是按钮的alertBox
export function alertBox(msg: string, btnName: string, type: string) {
    let confirmName: string = btnName == '确定' ? '确定' : '是'
    return ElMessageBox.alert(msg, '提示', {
        type: type,
        confirmButtonText: confirmName,
        dangerouslyUseHTMLString: true
    })
}

// 带确定取消按钮或者是否按钮的弹出提示框
export function confirmBox(msg: string, btnName: string, type: string) {
    let confirmName = btnName == '确定' ? '确定' : '是'
    let cancelsName = btnName == '确定' ? '取消' : '否'
    return ElMessageBox.confirm(msg, '提示', {
        type: type,
        confirmButtonText: confirmName,
        cancelButtonText: cancelsName,
        closeOnClickModal: false,
        closeOnPressEscape: false,
        dangerouslyUseHTMLString: true
    })
}

